package com.lmq.housekeeping;// housekeeping/ExplicitStatic.java
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Explicit static initialization with "static" clause

class Cup2{
  Cup2(int marker) {
    System.out.println("Cup(" + marker + ")");
  }
  void f(int marker) {
    System.out.println("f(" + marker + ")");
  }
}

class Cups2 {
  static Cup2 cup1=null;
  static Cup2 cup2;
  static {
    // TODO: field initialization rules===> static is first, then is  static block
    //        last is other field initialization
    cup1 = new Cup2(1);
    cup2 = new Cup2(2);
  }
  Cups2(int i) {
    System.out.println("Cups()"+ " "+ i);
  }

 Cup2 x =  new Cup2(3);
}

public class ExplicitStatic2 {
  public static void main(String[] args) {
    System.out.println("Inside main()");
    Cups2.cup1.f(99);                  // [1]
    System.out.println(Cups2.cup1);
  }
   static Cups2 cups1 = new Cups2(1112);  // [2]
  // static Cups cups2 = new Cups();  // [2]
}
/* Output:
Inside main()
Cup(1)
Cup(2)
f(99)
*/
